package com.tlgen.service;

import com.tlgen.mapper.RepairMapper;
import com.tlgen.model.Repair;
import com.tlgen.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: tlgen
 * @Discription:
 */
@Service
public class RepairService {

    @Autowired
    RepairMapper repairMapper;

    public RespPageBean getRepairByPage(Integer page, Integer size, Repair repair) {
        if (page != null && size != null) {
            page = (page-1) * size;
        }
        List<Repair> data = repairMapper.getRepairByPage(page, size, repair);
        Long total = repairMapper.getTotal(repair);
        RespPageBean bean = new RespPageBean();
        bean.setData(data);
        bean.setTotal(total);
        return bean;
    }

    public Integer addRepair(Repair repair) {
        repair.setCreateDate(new Date());
        return repairMapper.insertSelective(repair);
    }

    public Integer deleteRepairById(Integer id) {
        return repairMapper.deleteByPrimaryKey(id);
    }

    public Integer updateRepair(Repair repair) {
        return repairMapper.updateByPrimaryKeySelective(repair);
    }
}
